
/**
 * 
 * Similar to a CargoList, but basically just an array of quantities, one element for each possible Commodity. Also has a finite capacity.
 *
 */
public class CargoHold {

	private int commodity[];
	private int capacity;
	private int currentLoad;
	
	/**
	 * Constructor, needs to know how big the cargo hold is and how many different commodities there are.
	 * @param maxLoad
	 * @param numCommodities
	 */
	public CargoHold(int maxLoad, int numCommodities)
	{
		commodity = new int[numCommodities];
		capacity = maxLoad;
		currentLoad = 0;
	}
	
	/**
	 * 
	 * @param idx - Index into Commodity list
	 * @return number of units of this commodiy in the hold
	 */
	public int inventory(int idx)
	{
		return commodity[idx];
	}
	
	/**
	 * load cargo into the hold
	 * @param idx - Index into Commodity list
	 * @param count
	 */
	public void load(int idx, int count)
	{
		commodity[idx] += count;
		currentLoad += count;
	}
	
	/**
	 * Take cargo out of the hold
	 * @param idx - Index into Commodity list
	 * @param count
	 * @return number of units of that type left in hold after unloading
	 */
	public int unload(int idx, int count)
	{
		currentLoad -= count;
		commodity[idx] -= count;
		return commodity[idx];
	}
	
	/**
	 * 
	 * @return cargo bay total capacity
	 */
	public int totalBays()
	{
		return capacity;
	}
	
	/**
	 * 
	 * @return number of bays with nothing in them
	 */	
	public int emptyBays()
	{
		return capacity - currentLoad;
	}
	
	/**
	 * 
	 * @return number of bays with stuff in them
	 */
	public int filledBays()
	{
		return currentLoad;
	}
}
